package com.jy.api.domain;

import com.jy.api.service.StockTransactionService;
import com.jy.api.service.impl.SpringContextHolder;
import com.jy.api.signUpReq.stock.CapReq;
import com.jy.api.signUpReq.stock.InventoryReqData;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.util.Date;

/**
 * 库存实体
 * <p>
 * <p>
 * Created by hanxi on 2018/6/23.
 */
@Entity
@Data
@NoArgsConstructor
@Table(uniqueConstraints = @UniqueConstraint(name = "UK_INVENTORY", columnNames = {"productId", "quantity"}))
public class Inventory {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;
    private String storeId;
    private String productId;
    @ManyToOne
    private ProductType productType;
    /**
     * 库存商品名称
     */
    private String name;
    /**
     * 规格（每件数量）
     */
    private int capacity;
    /**
     * 库存数量
     */
    private int quantity;
    /**
     * 单价，每件进价
     */
    private double purchasePrice;

    /**
     * 是否显示标记
     */
    private boolean enabled = true;

    private int unitId;

    private String unitName;
    //TODO 需要把所有没跑数据的 给一个默认值 PRODUCT
    @Enumerated(EnumType.STRING)
    @Column(name = "mold")
    private ProductMold mold=ProductMold.PRODUCT;

    @Column(insertable = false, updatable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date addTime;
    @Column(insertable = false, updatable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date updateTime;


    public Inventory(InventoryReqData in, int quantity, double purchasePrice) {
        this.storeId = in.getStoreId();
        this.productId = in.getProductId();
        this.name = in.getName();
        this.capacity = in.getCapacity();
        this.quantity = quantity;
        this.purchasePrice = purchasePrice;
        this.mold=in.getMold();
    }

    public Inventory(CapReq req) {
        this.storeId = req.getStoreId();
        this.mold=req.getMold();
        this.productId = req.getProductId();
        this.name = req.getProductName();
        this.capacity = req.getCapacity();
        this.purchasePrice = req.getPurchasePrice();
    }

}
